package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：游记推荐控制器
 *
 * @package: cn.wolfcode.trip.admin.controller
 * @author: Patch
 * @date: 2019/5/23 2:42
 * 总结:
 */
@Controller
@RequestMapping("travelCommend")
public class TravelCommendController {
    @Autowired
    private ITravelCommendService travelCommendService;

    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") TravelCommendQueryObject qo) {
        // 设置根据推荐时间降序排序
        qo.setOrderBy("tc.schedule desc");
        model.addAttribute("pageInfo", travelCommendService.query(qo));
        return "travelCommend/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(TravelCommend travelCommend){
        JsonResult result = new JsonResult();
        try {
            travelCommendService.saveOrUpdate(travelCommend);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("亲，操作失败，请重试");
        }
        return  result;
    }


}
